<?php

namespace App\Http\Resources;

use App\Models\Mint;
use App\Models\Nft;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class UserResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        $nft_count = Nft::where('user_id', $this->id)->count();
        $doge_out_amount = Mint::where('user_id', $this->id)->sum('amount');
        return [
            'id' => $this->id,
            'address' => $this->address,
            'doge_address' => $this->doge_address,
            'nonce' => $this->nonce,
            'nft_count' => $nft_count,
            'doge_out_amount' => $doge_out_amount,
            'created_at' => $this->created_at
        ];
    }
}
